<%

dim nReqSeqNum

nReqSeqNum = Request.Form("numDirReqNum")

if nReqSeqNum <> "" then
'------------------------------------------------------ Validate whether the directive number exists -------------------------

	dim dllValidateDirectiveDelete
	dim sValidateDirectiveDelete

	Set dllValidateDirectiveDelete = Server.CreateObject("KeyTax.clsDirectives")
		sValidateDirectiveDelete = dllValidateDirectiveDelete.ValidateDirectiveDelete(session("KeyTaxUser"), nReqSeqNum)

	if sValidateDirectiveDelete <> "" then
		sErrorMessage = sValidateDirectiveDelete
	end if
	
	Set dllValidateDirectiveDelete = Nothing

'-----------------------------------------------------------------------------------------------------------------------------
else
	sErrorMessage = "Please enter a directive request number"
end if

if sErrorMessage = "" then
'------------------------------------------------------ Get the directive details from the database --------------------------

	dim dllGetDirectiveDetails
	dim sGetDirectiveDetails
	
	Set dllGetDirectiveDetails = Server.CreateObject("KeyTax.clsDirectives")
		sGetDirectiveDetails = dllGetDirectiveDetails.GetDirectiveDetails(nReqSeqNum, sTaxPayer, nIncomeTaxReferenceNo, nFundMembershipNo, nEmployeeNumber, nTaxYear, nLumpSum, nEmpID, nFundID, sRequestReason)
	
	Set dllGetDirectiveDetails = Nothing

end if


' -------------------------------------------------------- Get Fund data from database ----------------------------------------

	Dim dllFundDetails
	dim sFundDetails
	
	dim nFundNumber
	Dim sFundType
	Dim sFundTypeMeaning
	Dim sFundCreateRsnCode
	Dim sFundCreateRsnDesc
	Dim sFundName
	Dim sContactPerson
	Dim sTelCode
	Dim sTelNumber
	Dim sFundPost1
	Dim sFundPost2
	Dim sFundPost3
	Dim sFundPost4
	Dim sFundPostCode
	
	if nFundID <> "" then
		Set dllFundDetails = Server.CreateObject("KeyTax.clsFundDetail")
			sFundDetails = dllFundDetails.FundDetail(nFundID, nFundNumber, sFundType, sFundTypeMeaning, sFundCreateRsnCode, sFundCreateRsnDesc, sFundName, sContactPerson, sTelCode, sTelNumber, sFundPost1, sFundPost2, sFundPost3, sFundPost4, sFundPostCode)
			
		session("sOldFund") = "Yes"
	else
		nFundID = "null"
		session("sOldFund") = "No"
	end if 'nFundID <> ""
' -----------------------------------------------------------------------------------------------------------------------------





' -------------------------------------------------------- Get Employer data from database ------------------------------------
	
	'if loading a Form AD request, make sure that the PAYE reference number is filled in.
	if nEmpID <> "" then
		
		dim dllEmpDetails
		dim sEmpDetails
		
		'employer details
		Dim sEmployer
		dim nPAYERefNr
		Dim sEmpContactPerson
		Dim sEmpTelCode
		Dim sEmpTelNumber
		Dim sEmpHome1
		Dim sEmpHome2
		Dim sEmpHome3
		Dim sEmpHome4
		Dim sEmpHomeCode
		Dim sEmpPost1
		Dim sEmpPost2
		Dim sEmpPost3
		Dim sEmpPost4
		Dim sEmpPostCode
		
		Set dllEmpDetails = Server.CreateObject("KeyTax.clsEmployerDetail")
			sEmpDetails = dllEmpDetails.GetEmployerDetail(nEmpID, nPAYERefNr, sEmployer, sEmpContactPerson, sEmpTelCode, sEmpTelNumber, sEmpHome1, sEmpHome2, sEmpHome3, sEmpHome4, sEmpHomeCode, sEmpPost1, sEmpPost2, sEmpPost3, sEmpPost4, sEmpPostCode)
			
		
	end if 'nEmpID = ""
' -----------------------------------------------------------------------------------------------------------------------------
'Shane: Code changed by Shane on 26/05/2003
'1)Code changed to stop the system from deleting a dir req from the dir_request table but instead to flag
'it as deleted.
'2)Also check indicator in dir_parameters table to see if Extract process isn't already running
'if sSubmitRsn = "delete" then
		
'		dim dllDeleteDirective
'		dim sDeleteDirective
	
'		Set dllDeleteDirective = Server.CreateObject("KeyTax.clsDirectives")
'			sDeleteDirective = dllDeleteDirective.DeleteDirective(nReqSeqNum)
	
'		Set dllDeleteDirective = Nothing
	
'		if sDeleteDirective = "" AND sErrorMessage = "" then
'			sSaveMessage = "The request was successfully deleted."
'		end if 'sDeleteDirective = "" AND sErrorMessage = "" 
	
'end if 'sSubmitRsn = "delete"

if sSubmitRsn = "delete" then

	'Check dir_parameters table to see if extract process isn't already running
	dim dllCheckExtractProcess
	dim sStatus
	
	Set dllCheckExtractProcess = Server.CreateObject("KeyTax.clsDirectives")
	sStatus = dllCheckExtractProcess.CheckInProgress()
	
	Set dllCheckExtractProcess = Nothing
	
	If sStatus = "N" Then
		
		'If extract process is NOT currently running, Flag Directive Request as deleted
		dim dllDeleteDirective
		dim sDeleteDirective
	
		Set dllDeleteDirective = Server.CreateObject("KeyTax.clsDirectives")
		sDeleteDirective = dllDeleteDirective.DeleteRequest(CStr(nReqSeqNum))
	
		Set dllDeleteDirective = Nothing
	
		if sDeleteDirective = "" AND sErrorMessage = "" then
			sSaveMessage = "The request was successfully deleted."
		end if 'sDeleteDirective = "" AND sErrorMessage = "" 
	Else
		sErrorMessage = "The extract process to SARS is already in progress. This directive request cannot be deleted."	
	End If
	
end if 'sSubmitRsn = "delete"

%>